package com.yanqu.road.server.cmd.vehicle;

import com.yanqu.road.entity.config.vehicle.VehicleModifySkillResult;
import com.yanqu.road.logic.pb.VehiclePb;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/9/28 10:17
 */
@Cmd(code = GameProtocol.S_VEHICLE_SKILL_MODIFY_AUTO, desc = "珍兽技能改装自动化")
public class VehicleSkillModifyAutoCmd extends AbstractCommand {
    private String vehicleUid;
    private int skillType;
    private int skillPos;
    private boolean isCustomize;
    private long goalVal;
    private String costLimit;
    private int markId;
    private boolean isBegin;
    private VehicleModifySkillResult result;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VehicleProto.VehicleSkillModifyAutoReqMsg msg = VehicleProto.VehicleSkillModifyAutoReqMsg.parseFrom(packet.getBytes());
        vehicleUid = msg.getVehicleUid();
        skillType = msg.getGoalType();
        skillPos = msg.getSkillPos();
        isCustomize = msg.getIsCustomize();
        goalVal = msg.getGoalVal();
        costLimit = msg.getCostLimit();
        markId = msg.getMarkId();
        isBegin = msg.getIsBegin();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        result = player.getModule(VehicleModule.class).modifyVehicleSkillAuto(vehicleUid, skillType, skillPos, isCustomize, goalVal, costLimit, isBegin);
    }

    @Override
    public void sendData(GamePlayer player) {
        VehicleProto.VehicleSkillModifyAutoRespMsg.Builder respMsg = VehicleProto.VehicleSkillModifyAutoRespMsg.newBuilder();
        respMsg.setMarkId(markId);
        respMsg.setRet(result.getRet());
        if (result.getVehicleSkill() != null) {
            respMsg.setVehicleUid(vehicleUid);
            respMsg.setIsReplace(result.isReplace());
            VehicleProto.VehicleSkillTempMsg.Builder temp = VehiclePb.parseVehicleSkillTempMsg(result.getVehicleSkill());
            if(null != temp) {
                respMsg.setSkill(temp);
            }
        }
        player.sendPacket(ClientProtocol.U_VEHICLE_SKILL_MODIFY_AUTO, respMsg);
    }
}
